package org.seven.jrdp.web.t;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.seven.jrdp.biz.t.model.TFxd;
import org.seven.jrdp.biz.t.model.TRkd;
import org.seven.jrdp.biz.t.service.TFxdService;
import org.seven.jrdp.commons.model.Result;
import org.seven.jrdp.commons.mybatis.model.PageRequest;
import org.seven.jrdp.commons.util.JsonUtils;
import org.seven.jrdp.commons.util.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/mgt/t/fxd")
public class TFxdController {
	@Autowired
	private TFxdService tFxdService;

	@GetMapping("/{view}")
	public ModelAndView view(@PathVariable String view) {
		return new ModelAndView("mgt/t/fxd/fxd_" + view);
	}

	@PostMapping("/find")
	public PageInfo<Map<String, Object>> find(PageRequest pageRequest, HttpServletRequest request) {
		Map<String, Object> map = ServletUtils.getSearchParams(request);
		PageInfo<Map<String, Object>> page = tFxdService.find(map, pageRequest);
		return page;
	}

	@RequestMapping("/rkfx/find")
	public List<Map<String, Object>> findRkfx(String cpbh) {
		List<Map<String, Object>> list = tFxdService.findRkfx(cpbh);
		return list;
	}

	@RequestMapping("/ckfx/find")
	public List<Map<String, Object>> findCkfx(String cpbh) {
		List<Map<String, Object>> list = tFxdService.findCkfx(cpbh);
		return list;
	}

	@PostMapping("/rkfx")
	public Result saveRkfx(String json) {
		List<TFxd> list = JsonUtils.getList(json, TFxd.class);
		tFxdService.saveRkfx(list);
		return Result.SUCCESS;
	}

	@PostMapping("/ckfx")
	public Result saveCkfx(TRkd tRkd, String json) {
		List<TFxd> list = JsonUtils.getList(json, TFxd.class);
		tFxdService.saveCkfx(tRkd, list);
		return Result.SUCCESS;
	}
}